package pl.pr3sto.security


class ProfileController {
	
	LoginValidationService loginValidationService

    def index = { }
	
	def authenticationBar = {
		if(!session.profile) {
			session.profile = Profile.getGuest()
		}
		return [profile: session.profile]
	}
	
	def loginUser = {
		Profile profile = loginValidationService.validateLogin(params.login, params.pass)
		if (profile != null)
			session.profile = profile
		else
			flash.message = 'login.error'
		render(view: "authenticationBar", model:[profile: session.profile])
	}
	
	def logoutUser = {
		session.profile = Profile.getGuest()	
		render(view: "authenticationBar", model:[profile: session.profile])
	}
}
